package com.hy.admin.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hy.admin.enums.EnumIsFree;
import com.hy.admin.helper.request.*;
import org.apache.commons.httpclient.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.hy.admin.entity.CourseEntity;
import com.hy.admin.entity.CourseInfoEntity;
import com.hy.admin.helper.response.ContentResponse;
import com.hy.admin.helper.response.CourseIntroResponse;
import com.hy.admin.helper.response.CourseResponse;
import com.hy.admin.helper.response.OrderResponse;
import com.hy.admin.service.CourseService;
import com.hy.core.request.ApiRequestDTO;
import com.hy.core.response.ApiResponseDTO;
import com.hy.core.response.ServicesResult;

/**
 * Created by yangqq on 18/4/3.
 * 课程
 */
@RestController
@RequestMapping("/api/course")
public class CourseController {

    protected final Logger logBase = LoggerFactory.getLogger(CourseController.class);
    @Autowired
    private CourseService courseService;

    @RequestMapping(value = "/index", method = RequestMethod.POST)
    public ApiResponseDTO index(@RequestBody final ApiRequestDTO apiRequestDTO,HttpServletRequest request) {
        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        //打印请求参数
        logBase.info("course_index_request:{}", gson.toJson(apiRequestDTO));
        ApiResponseDTO apiResponseDTO = new ApiResponseDTO(HttpStatus.SC_ACCEPTED, "", apiRequestDTO.getUuid());
        //获取请求对象index
        CourseRequest courseRequest= gson.fromJson(apiRequestDTO.getRequestData(), CourseRequest.class);
        //获取请求对象
        PersonalRequest personalRequest= gson.fromJson(apiRequestDTO.getRequestData(), PersonalRequest.class);
        //获取请求数据
        ServicesResult<List<CourseInfoEntity>> courseResponse = courseService.allCourse(personalRequest.getPageNum(), personalRequest.getPageSize());
        apiResponseDTO.initServicesResult(courseResponse);
        //处理返回对象
        apiResponseDTO.setResponseData(gson.toJson(courseResponse.getResult()));
        logBase.info("course_index_response:{}", gson.toJson(apiResponseDTO));
        return apiResponseDTO;
    }

    /**
     * 已购课程
     * @param apiRequestDTO
     * @param request
     * @return
     */
    @RequestMapping(value = "/own", method = RequestMethod.POST)
    public ApiResponseDTO own(@RequestBody final ApiRequestDTO apiRequestDTO,HttpServletRequest request) {
        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        //打印请求参数
        logBase.info("course_own_request:{}", gson.toJson(apiRequestDTO));
        ApiResponseDTO apiResponseDTO = new ApiResponseDTO(HttpStatus.SC_ACCEPTED, "", apiRequestDTO.getUuid());
        //获取请求对象
        CourseRequest courseRequest= gson.fromJson(apiRequestDTO.getRequestData(), CourseRequest.class);
        //获取请求数据
        ServicesResult<List<CourseInfoEntity>> courseResponse = courseService.listByMemberBuy(courseRequest.getMemberId(),courseRequest.getPageNum(),courseRequest.getPageSize());
        apiResponseDTO.initServicesResult(courseResponse);
        //处理返回对象
        apiResponseDTO.setResponseData(gson.toJson(courseResponse.getResult()));
        logBase.info("course_own_response:{}", gson.toJson(apiResponseDTO));
        return apiResponseDTO;
    }

    /**
     * 课程系列下的所有课程
     * @param apiRequestDTO
     * @param request
     * @return
     */
    @RequestMapping(value = "/series", method = RequestMethod.POST)
    public ApiResponseDTO series(@RequestBody final ApiRequestDTO apiRequestDTO,HttpServletRequest request) {
        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        //打印请求参数
        logBase.info("course_series_request:{}", gson.toJson(apiRequestDTO));
        ApiResponseDTO apiResponseDTO = new ApiResponseDTO(HttpStatus.SC_ACCEPTED, "", apiRequestDTO.getUuid());
        //获取请求对象
        CourseRequest courseRequest= gson.fromJson(apiRequestDTO.getRequestData(), CourseRequest.class);
        //获取请求数据
        ServicesResult<List<CourseInfoEntity>> courseResponse = courseService.listBySeriesId(courseRequest.getSeriesId());
        apiResponseDTO.initServicesResult(courseResponse);
        //处理返回对象
        apiResponseDTO.setResponseData(gson.toJson(courseResponse.getResult()));
        logBase.info("course_series_response:{}", gson.toJson(apiResponseDTO));
        return apiResponseDTO;
    }

    /**
     * 课程详情
     * @param apiRequestDTO
     * @return
     */
    @RequestMapping(value = "/detail", method = RequestMethod.POST)
    public ApiResponseDTO detail(@RequestBody final ApiRequestDTO apiRequestDTO) {
        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        //打印请求参数
        logBase.info("course_detail_request:{}", gson.toJson(apiRequestDTO));
        ApiResponseDTO apiResponseDTO = new ApiResponseDTO(HttpStatus.SC_ACCEPTED, "", apiRequestDTO.getUuid());
        //获取请求对象
        CourseRequest courseRequest= gson.fromJson(apiRequestDTO.getRequestData(), CourseRequest.class);
        //获取请求数据
        ServicesResult<CourseResponse> courseResponse = courseService.detail(courseRequest.getCourseId(),courseRequest.getMemberId());
        apiResponseDTO.initServicesResult(courseResponse);
        //处理返回对象
        apiResponseDTO.setResponseData(gson.toJson(courseResponse.getResult()));
        logBase.info("course_detail_response:{}", gson.toJson(apiResponseDTO));
        return apiResponseDTO;
    }

    /**
     * 课程简介
     * @param apiRequestDTO
     * @param request
     * @return
     */
    @RequestMapping(value = "/introduce", method = RequestMethod.POST)
    public ApiResponseDTO introduce(@RequestBody final ApiRequestDTO apiRequestDTO,HttpServletRequest request) {
        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        //打印请求参数
        logBase.info("course_introduce_request:{}", gson.toJson(apiRequestDTO));
        ApiResponseDTO apiResponseDTO = new ApiResponseDTO(HttpStatus.SC_ACCEPTED, "", apiRequestDTO.getUuid());
        //获取请求对象
        CourseRequest courseRequest= gson.fromJson(apiRequestDTO.getRequestData(), CourseRequest.class);
        //获取请求数据
        ServicesResult<CourseIntroResponse> courseResponse = courseService.introduce(courseRequest.getCourseId());
        apiResponseDTO.initServicesResult(courseResponse);
        //处理返回对象
        apiResponseDTO.setResponseData(gson.toJson(courseResponse.getResult()));
        logBase.info("course_introduce_response:{}", gson.toJson(apiResponseDTO));
        return apiResponseDTO;
    }

    /**
     * 教师的所有课程
     * @param apiRequestDTO
     * @param request
     * @return
     */
    @RequestMapping(value = "/teacher", method = RequestMethod.POST)
    public ApiResponseDTO teacher(@RequestBody final ApiRequestDTO apiRequestDTO,HttpServletRequest request) {
        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        //打印请求参数
        logBase.info("course_teacher_request:{}", gson.toJson(apiRequestDTO));
        ApiResponseDTO apiResponseDTO = new ApiResponseDTO(HttpStatus.SC_ACCEPTED, "", apiRequestDTO.getUuid());
        //获取请求对象
        CourseRequest courseRequest= gson.fromJson(apiRequestDTO.getRequestData(), CourseRequest.class);
        //获取请求数据
        ServicesResult<List<CourseResponse>> courseResponse = courseService.listByMemberId(courseRequest.getMemberId(),courseRequest.getPageNum(),courseRequest.getPageSize());
        apiResponseDTO.initServicesResult(courseResponse);
        //处理返回对象
        apiResponseDTO.setResponseData(gson.toJson(courseResponse.getResult()));
        logBase.info("course_teacher_response:{}", gson.toJson(apiResponseDTO));
        return apiResponseDTO;
    }

    @RequestMapping(value = "/search", method = RequestMethod.POST)
    public ApiResponseDTO search(@RequestBody final ApiRequestDTO apiRequestDTO,HttpServletRequest request) {
        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        //打印请求参数
        logBase.info("course_search_request:{}", gson.toJson(apiRequestDTO));
        ApiResponseDTO apiResponseDTO = new ApiResponseDTO(HttpStatus.SC_ACCEPTED, "", apiRequestDTO.getUuid());
        //获取请求对象
        CourseRequest courseRequest= gson.fromJson(apiRequestDTO.getRequestData(), CourseRequest.class);
        //获取请求数据
        ServicesResult<List<CourseInfoEntity>> courseResponse = courseService.search(courseRequest.getKeyword());
        apiResponseDTO.initServicesResult(courseResponse);
        //处理返回对象
        apiResponseDTO.setResponseData(gson.toJson(courseResponse.getResult()));
        logBase.info("course_search_response:{}", gson.toJson(apiResponseDTO));
        return apiResponseDTO;
    }

    /**
     * 购买课程
     * @param apiRequestDTO
     * @param request
     * @return
     */
    @RequestMapping(value = "/buy", method = RequestMethod.POST)
    public ApiResponseDTO buy(@RequestBody final ApiRequestDTO apiRequestDTO,HttpServletRequest request) {
        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        //打印请求参数
        logBase.info("course_buy_request:{}", gson.toJson(apiRequestDTO));
        ApiResponseDTO apiResponseDTO = new ApiResponseDTO(HttpStatus.SC_ACCEPTED, "", apiRequestDTO.getUuid());
        //获取请求对象
        CourseRequest courseRequest= gson.fromJson(apiRequestDTO.getRequestData(), CourseRequest.class);
        //获取请求数据
        ServicesResult<OrderResponse> courseResponse = courseService.buy(courseRequest.getMemberId(), courseRequest.getCourseId());
        apiResponseDTO.initServicesResult(courseResponse);
        //处理返回对象
        apiResponseDTO.setResponseData(gson.toJson(courseResponse.getResult()));
        logBase.info("course_buy_response:{}", gson.toJson(apiResponseDTO));
        return apiResponseDTO;
    }

    /**
     * 上传课程
     * @param apiRequestDTO
     * @param file
     * @return
     */
    @RequestMapping(value = "/addWeb", method = RequestMethod.POST)
    public ApiResponseDTO addWeb(ApiRequestDTO apiRequestDTO,@RequestParam("files") MultipartFile file,@RequestParam(value = "image",required = false) MultipartFile image) {

        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        //打印请求参数
        logBase.info("course_addWeb_request:{}", gson.toJson(apiRequestDTO));
        ApiResponseDTO apiResponseDTO = new ApiResponseDTO(HttpStatus.SC_ACCEPTED, "", apiRequestDTO.getUuid());

        //获取请求对象
        CourseEntity courseEntity= gson.fromJson(apiRequestDTO.getRequestData(), CourseEntity.class);

        //获取数据
        ServicesResult<Boolean> servicesResult = null;
        try {
            servicesResult = courseService.addWithFile(courseEntity, file, image);
        } catch (Exception e) {
            e.printStackTrace();
            servicesResult = new ServicesResult<>();
            servicesResult.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
            servicesResult.setStatusMsg("系统异常");
        }
        apiResponseDTO.initServicesResult(servicesResult);
        //处理返回对象
        apiResponseDTO.setResponseData(gson.toJson(servicesResult.getResult()));
        logBase.info("course_addWeb_response:{}", gson.toJson(apiResponseDTO));
        return apiResponseDTO;
    }

    /**
     * 上传课程---本地上传文件到阿里云oss
     * @param apiRequestDTO
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ApiResponseDTO add(@RequestBody final ApiRequestDTO apiRequestDTO) {

        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        //打印请求参数
        logBase.info("course_add_request:{}", gson.toJson(apiRequestDTO));
        ApiResponseDTO apiResponseDTO = new ApiResponseDTO(HttpStatus.SC_ACCEPTED, "", apiRequestDTO.getUuid());

        //获取请求对象
        CourseEntity courseEntity= gson.fromJson(apiRequestDTO.getRequestData(), CourseEntity.class);

        //获取数据
        ServicesResult<Boolean> servicesResult  = courseService.add(courseEntity);
        apiResponseDTO.initServicesResult(servicesResult);
        //处理返回对象
        apiResponseDTO.setResponseData(gson.toJson(servicesResult.getResult()));
        logBase.info("course_add_response:{}", gson.toJson(apiResponseDTO));
        return apiResponseDTO;
    }

    /**
     * 增加点击量
     * @param apiRequestDTO
     * @return
     */
    @RequestMapping(value = "/click", method = RequestMethod.POST)
    public ApiResponseDTO click(@RequestBody final ApiRequestDTO apiRequestDTO) {

        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        //打印请求参数
        logBase.info("course_click_request:{}", gson.toJson(apiRequestDTO));
        ApiResponseDTO apiResponseDTO = new ApiResponseDTO(HttpStatus.SC_ACCEPTED, "", apiRequestDTO.getUuid());

        //获取请求对象
        CourseRequest courseRequest= gson.fromJson(apiRequestDTO.getRequestData(), CourseRequest.class);

        //获取数据
        ServicesResult<Boolean> servicesResult = courseService.addClickNum(courseRequest.getCourseId());
        apiResponseDTO.initServicesResult(servicesResult);
        //处理返回对象
        apiResponseDTO.setResponseData(gson.toJson(servicesResult.getResult()));
        logBase.info("course_click_response:{}", gson.toJson(apiResponseDTO));
        return apiResponseDTO;
    }

    /**
     * 下载音频文件
     * @param apiRequestDTO
     * @return
     */
    @RequestMapping(value = "/download", method = RequestMethod.POST)
    public ApiResponseDTO download(@RequestBody final ApiRequestDTO apiRequestDTO) {

        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        //打印请求参数
        logBase.info("course_download_request:{}", gson.toJson(apiRequestDTO));
        ApiResponseDTO apiResponseDTO = new ApiResponseDTO(HttpStatus.SC_ACCEPTED, "", apiRequestDTO.getUuid());

        //获取请求对象
        CourseDownloadRequest courseRequest= gson.fromJson(apiRequestDTO.getRequestData(), CourseDownloadRequest.class);

        //获取数据
        ServicesResult<Boolean> servicesResult = courseService.downloadFile(courseRequest.getCourseId(), courseRequest.getLocalFilePath());
        apiResponseDTO.initServicesResult(servicesResult);
        //处理返回对象
        apiResponseDTO.setResponseData(gson.toJson(servicesResult.getResult()));
        logBase.info("course_download_response:{}", gson.toJson(apiResponseDTO));
        return apiResponseDTO;
    }

    /**
     * 查询语音转换结果
     * @param apiRequestDTO
     * @return
     */
    @RequestMapping(value = "/content", method = RequestMethod.POST)
    public ApiResponseDTO getContent(@RequestBody final ApiRequestDTO apiRequestDTO) {

        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        //打印请求参数
        logBase.info("course_content_request:{}", gson.toJson(apiRequestDTO));
        ApiResponseDTO apiResponseDTO = new ApiResponseDTO(HttpStatus.SC_ACCEPTED, "", apiRequestDTO.getUuid());

        //获取请求对象
        CourseRequest courseRequest= gson.fromJson(apiRequestDTO.getRequestData(), CourseRequest.class);

        //获取数据
        ServicesResult<ContentResponse> servicesResult = courseService.getContent(courseRequest.getCourseId());
        apiResponseDTO.initServicesResult(servicesResult);
        //处理返回对象
        apiResponseDTO.setResponseData(gson.toJson(servicesResult.getResult()));
        logBase.info("course_content_response:{}", gson.toJson(apiResponseDTO));
        return apiResponseDTO;
    }

    /**
     * 审核教师
     * @param apiRequestDTO
     * @return
     */
    @RequestMapping(value = "/audit", method = RequestMethod.POST)
    public ApiResponseDTO audit(@RequestBody final ApiRequestDTO apiRequestDTO) {

        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        //打印请求参数
        logBase.info("course_audit_request:{}", gson.toJson(apiRequestDTO));
        ApiResponseDTO apiResponseDTO = new ApiResponseDTO(HttpStatus.SC_ACCEPTED, "", apiRequestDTO.getUuid());

        //获取请求对象
        CourseRequest courseRequest= gson.fromJson(apiRequestDTO.getRequestData(), CourseRequest.class);

        //获取数据
        ServicesResult<Boolean> servicesResult = courseService.audit(courseRequest.getCourseId(),courseRequest.getAuditStatus());
        apiResponseDTO.initServicesResult(servicesResult);
        //处理返回对象
        apiResponseDTO.setResponseData(gson.toJson(servicesResult.getResult()));
        logBase.info("course_audit_response:{}", gson.toJson(apiResponseDTO));
        return apiResponseDTO;
    }
    
    
    /**
     * 修改语音转换结果
     * @param apiRequestDTO
     * @return
     */
    @RequestMapping(value = "/content_upd", method = RequestMethod.POST)
    public ApiResponseDTO updateContent(@RequestBody final ApiRequestDTO apiRequestDTO) {

        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        //打印请求参数
        logBase.info("course_content_request:{}", gson.toJson(apiRequestDTO));
        ApiResponseDTO apiResponseDTO = new ApiResponseDTO(HttpStatus.SC_ACCEPTED, "", apiRequestDTO.getUuid());

        //获取请求对象
        CourseRequest courseRequest= gson.fromJson(apiRequestDTO.getRequestData(), CourseRequest.class);

        ServicesResult<Boolean> servicesResult = courseService.updateContent(courseRequest.getCourseId(), courseRequest.getContent());
        apiResponseDTO.initServicesResult(servicesResult);
        //处理返回对象
        apiResponseDTO.setResponseData(gson.toJson(servicesResult.getResult()));
        logBase.info("course_content_response:{}", gson.toJson(apiResponseDTO));
        return apiResponseDTO;
    }

    /**
     * 修改语音转换结果
     * @param apiRequestDTO
     * @return
     */
    @RequestMapping(value = "/price_upd", method = RequestMethod.POST)
    public ApiResponseDTO updatePrice(@RequestBody final ApiRequestDTO apiRequestDTO) {

        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        //打印请求参数
        logBase.info("course_price_update_request:{}", gson.toJson(apiRequestDTO));
        ApiResponseDTO apiResponseDTO = new ApiResponseDTO(HttpStatus.SC_ACCEPTED, "", apiRequestDTO.getUuid());

        //获取请求对象
        CourseRequest courseRequest= gson.fromJson(apiRequestDTO.getRequestData(), CourseRequest.class);

        ServicesResult<Boolean> servicesResult = courseService.updatePrice(courseRequest.getCourseId(), courseRequest.getPrice());
        apiResponseDTO.initServicesResult(servicesResult);
        //处理返回对象
        apiResponseDTO.setResponseData(gson.toJson(servicesResult.getResult()));
        logBase.info("course_price_update_response:{}", gson.toJson(apiResponseDTO));
        return apiResponseDTO;
    }

    /**
     * 查询免费课程
     * @param apiRequestDTO
     * @return
     */
    @RequestMapping(value = "/free", method = RequestMethod.POST)
    public ApiResponseDTO free(@RequestBody final ApiRequestDTO apiRequestDTO) {

        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        //打印请求参数
        logBase.info("course_free_request:{}", gson.toJson(apiRequestDTO));
        ApiResponseDTO apiResponseDTO = new ApiResponseDTO(HttpStatus.SC_ACCEPTED, "", apiRequestDTO.getUuid());

        //获取请求对象
        CourseRequest courseRequest= gson.fromJson(apiRequestDTO.getRequestData(), CourseRequest.class);

        ServicesResult<List<CourseInfoEntity>> servicesResult = courseService.freeCourse(courseRequest.getNickName(), courseRequest.getTitle(), courseRequest.getPageNum(), courseRequest.getPageSize());
        apiResponseDTO.initServicesResult(servicesResult);
        //处理返回对象
        apiResponseDTO.setResponseData(gson.toJson(servicesResult.getResult()));
        logBase.info("course_free_response:{}", gson.toJson(apiResponseDTO));
        return apiResponseDTO;
    }

    /**
     * 查询收费课程
     * @param apiRequestDTO
     * @return
     */
    @RequestMapping(value = "/charge", method = RequestMethod.POST)
    public ApiResponseDTO charge(@RequestBody final ApiRequestDTO apiRequestDTO) {

        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        //打印请求参数
        logBase.info("course_charge_request:{}", gson.toJson(apiRequestDTO));
        ApiResponseDTO apiResponseDTO = new ApiResponseDTO(HttpStatus.SC_ACCEPTED, "", apiRequestDTO.getUuid());

        //获取请求对象
        CourseRequest courseRequest= gson.fromJson(apiRequestDTO.getRequestData(), CourseRequest.class);

        ServicesResult<List<CourseInfoEntity>> servicesResult = courseService.chargeCourse(courseRequest.getNickName(), courseRequest.getTitle(), courseRequest.getPageNum(), courseRequest.getPageSize());
        apiResponseDTO.initServicesResult(servicesResult);
        //处理返回对象
        apiResponseDTO.setResponseData(gson.toJson(servicesResult.getResult()));
        logBase.info("course_charge_response:{}", gson.toJson(apiResponseDTO));
        return apiResponseDTO;
    }

    /**
     * 更新收费置顶课程
     * @param apiRequestDTO
     * @return
     */
    @RequestMapping(value = "/setTopCharge", method = RequestMethod.POST)
    public ApiResponseDTO setTop(@RequestBody final ApiRequestDTO apiRequestDTO) {

        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        //打印请求参数
        logBase.info("course_setTopCharge_request:{}", gson.toJson(apiRequestDTO));
        ApiResponseDTO apiResponseDTO = new ApiResponseDTO(HttpStatus.SC_ACCEPTED, "", apiRequestDTO.getUuid());

        //获取请求对象
        SetTopRequest setTopRequest= gson.fromJson(apiRequestDTO.getRequestData(), SetTopRequest.class);

        ServicesResult<Boolean> servicesResult = null;
        try {
            servicesResult = courseService.setTop(EnumIsFree.NO.getId(), setTopRequest.getIds());
        } catch (Exception e) {
            e.printStackTrace();
            servicesResult.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
            servicesResult.setStatusMsg("系统异常");
        }
        apiResponseDTO.initServicesResult(servicesResult);
        //处理返回对象
        apiResponseDTO.setResponseData(gson.toJson(servicesResult.getResult()));
        logBase.info("course_setTopCharge_response:{}", gson.toJson(apiResponseDTO));
        return apiResponseDTO;
    }

    /**
     * 更新免费置顶课程
     * @param apiRequestDTO
     * @return
     */
    @RequestMapping(value = "/setTopFree", method = RequestMethod.POST)
    public ApiResponseDTO setTopFree(@RequestBody final ApiRequestDTO apiRequestDTO) {

        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        //打印请求参数
        logBase.info("course_setTopFree_request:{}", gson.toJson(apiRequestDTO));
        ApiResponseDTO apiResponseDTO = new ApiResponseDTO(HttpStatus.SC_ACCEPTED, "", apiRequestDTO.getUuid());

        //获取请求对象
        SetTopRequest setTopRequest= gson.fromJson(apiRequestDTO.getRequestData(), SetTopRequest.class);

        ServicesResult<Boolean> servicesResult = null;
        try {
            servicesResult = courseService.setTop(EnumIsFree.YES.getId(), setTopRequest.getIds());
        } catch (Exception e) {
            e.printStackTrace();
            servicesResult.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
            servicesResult.setStatusMsg("系统异常");
        }
        apiResponseDTO.initServicesResult(servicesResult);
        //处理返回对象
        apiResponseDTO.setResponseData(gson.toJson(servicesResult.getResult()));
        logBase.info("course_setTopFree_response:{}", gson.toJson(apiResponseDTO));
        return apiResponseDTO;
    }

    /**
     * 更新免费置顶课程
     * @param apiRequestDTO
     * @return
     */
    @RequestMapping(value = "/cancelTop", method = RequestMethod.POST)
    public ApiResponseDTO cancelTop(@RequestBody final ApiRequestDTO apiRequestDTO) {

        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        //打印请求参数
        logBase.info("course_cancelTop_request:{}", gson.toJson(apiRequestDTO));
        ApiResponseDTO apiResponseDTO = new ApiResponseDTO(HttpStatus.SC_ACCEPTED, "", apiRequestDTO.getUuid());

        //获取请求对象
        SetTopRequest setTopRequest= gson.fromJson(apiRequestDTO.getRequestData(), SetTopRequest.class);

        ServicesResult<Boolean> servicesResult = courseService.cancelTop(setTopRequest.getIds());
        apiResponseDTO.initServicesResult(servicesResult);
        //处理返回对象
        apiResponseDTO.setResponseData(gson.toJson(servicesResult.getResult()));
        logBase.info("course_cancelTop_response:{}", gson.toJson(apiResponseDTO));
        return apiResponseDTO;
    }

    /**
     * 设置免费课程类型
     * @param apiRequestDTO
     * @return
     */
    @RequestMapping(value = "/setType", method = RequestMethod.POST)
    public ApiResponseDTO setType(@RequestBody final ApiRequestDTO apiRequestDTO) {

        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        //打印请求参数
        logBase.info("course_setType_request:{}", gson.toJson(apiRequestDTO));
        ApiResponseDTO apiResponseDTO = new ApiResponseDTO(HttpStatus.SC_ACCEPTED, "", apiRequestDTO.getUuid());

        //获取请求对象
        SetTypeRequest setTypeRequest= gson.fromJson(apiRequestDTO.getRequestData(), SetTypeRequest.class);

        ServicesResult<Boolean> servicesResult = null;
        try {
            servicesResult = courseService.setCourseType(setTypeRequest.getId(), setTypeRequest.getCourseType());
        } catch (Exception e) {
            e.printStackTrace();
            servicesResult.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
            servicesResult.setStatusMsg("系统异常");
        }
        apiResponseDTO.initServicesResult(servicesResult);
        //处理返回对象
        apiResponseDTO.setResponseData(gson.toJson(servicesResult.getResult()));
        logBase.info("course_setType_response:{}", gson.toJson(apiResponseDTO));
        return apiResponseDTO;
    }

    /**
     * 上传课程
     * @param apiRequestDTO
     * @param file
     * @return
     */
    @RequestMapping(value = "/updateFace", method = RequestMethod.POST)
    public ApiResponseDTO updateFace(ApiRequestDTO apiRequestDTO,@RequestParam("files") MultipartFile file) {

        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        //打印请求参数
        logBase.info("course_updateFace_request:{}", gson.toJson(apiRequestDTO));
        ApiResponseDTO apiResponseDTO = new ApiResponseDTO(HttpStatus.SC_ACCEPTED, "", apiRequestDTO.getUuid());

        //获取请求对象
        CourseRequest courseRequest= gson.fromJson(apiRequestDTO.getRequestData(), CourseRequest.class);

        //获取数据
        ServicesResult<Boolean> servicesResult = null;
        try {
            servicesResult = courseService.updateFaceImg(courseRequest.getCourseId(), file);
        } catch (Exception e) {
            e.printStackTrace();
            servicesResult = new ServicesResult<>();
            servicesResult.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
            servicesResult.setStatusMsg("系统异常");
        }
        apiResponseDTO.initServicesResult(servicesResult);
        //处理返回对象
        apiResponseDTO.setResponseData(gson.toJson(servicesResult.getResult()));
        logBase.info("course_updateFace_response:{}", gson.toJson(apiResponseDTO));
        return apiResponseDTO;
    }
}
